


<input id="img" type="file" size="45" name="img" class="input">
<button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">Upload</button>
<img id="loading" src="<?php echo Yii::app()->theme->baseUrl . '/img/loading.gif' ?>" style="display:none;">
<div><img id="uploadImg" src="" /></div>

<script type="text/javascript">
    function ajaxFileUpload() {
        loading();//动态加载小图标
        $.ajaxFileUpload({
            url: '<?php echo $this->createUrl('/upload/post') ?>',
            secureuri: false,
            fileElementId: 'img',
            dataType: 'json',
            success: function(data) {
                $("#uploadImg").attr('src', "<?php echo Yii::app()->baseUrl . "/upload/" ?>" + data);
            }

        })
        return false;
    }
    function loading() {
        $("#loading").ajaxStart(function() {
            $(this).show();
        }).ajaxComplete(
                function() {
                    $(this).hide();
                });
    }
</script>